﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace _4DJackPot
{
    public partial class CompanyGameInformation : Dock
    {
        public String game_id { get; set; }
        public String draw_date { get; set; }
        public String company_id {get; set; }
        public String company_name { get; set; }
        public String company_logo_url { get; set; }

        public CompanyGameInformation(String game_id, String company_id, String draw_date)
        {
            InitializeComponent();

            this.game_id = game_id;
            this.company_id = company_id;
            this.draw_date = draw_date;

            Company company = new Company(company_id);
            company_name = company.companyNameString;
            company_logo_url = company.companyLogoUrl;

            lblGameIDValue.Text = game_id;
            lblCompanyValue.Text = company_name;
            lblDrawDateValue.Text = draw_date;
            pbCompanyLogo.Image = (Bitmap)global::_4DJackPot.Properties.Resources.ResourceManager.GetObject(company_logo_url);

            DateTime drawDate = DateTime.Parse(this.draw_date);
            if (drawDate.Date > DateTime.Today.Date)
            {
                lblNoDraw.Visible = true;
            }
            else
            {
                showPrizes();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void showPrizes()
        {
            string selectQueryString =
                "select prize_types.prize_name, game_winning_numbers.number, (select count(bets.bet_id) from bet_winnings, bets where bet_winnings.bet_id = bets.bet_id and bets.game_id = game_winning_numbers.game_id and bet_winnings.prize_type_id = prize_types.prize_type_id), Format((select sum(bet_winnings.bet_winning_amount) from bet_winnings, bets where bet_winnings.bet_id = bets.bet_id and bets.game_id = game_winning_numbers.game_id and bet_winnings.prize_type_id = prize_types.prize_type_id), 'General Number') from prize_types, game_winning_numbers where prize_types.prize_type_id = game_winning_numbers.prize_type_id and game_id=" + this.game_id + " order by game_winning_numbers.prize_type_id asc;";
            
            Global.dBCmd.CommandText = selectQueryString;
            System.Data.OleDb.OleDbDataReader reader = Global.dBCmd.ExecuteReader();
            ArrayList prizeTypes = new ArrayList();
            int i = 0;
            while (reader.Read())
            {
                dgvPrizes.Rows.Add(1);
                dgvPrizes["Prize", i].Value = reader[0].ToString();
                dgvPrizes["DrawNumber", i].Value = Int32.Parse(reader[1].ToString()).ToString("0000");
                if (reader[2].ToString().Length == 0)
                    dgvPrizes["AwardedPeople", i].Value = "0";
                else
                    dgvPrizes["AwardedPeople", i].Value = reader[2].ToString();
                if (reader[3].ToString().Length == 0)
                    dgvPrizes["TotalAwardedAmount", i].Value = "\\0";
                else
                    dgvPrizes["TotalAwardedAmount", i].Value = "\\" + reader[3].ToString();
                i++;
            }
            reader.Close();

        }

    }
}
